home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / Demos_Files / DLL / MomentumPrepost.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  2.6 KB  |  80 lines

  1. // Dynamic link library implementation of NeuroSolutions Momentum component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /*****************************/
  6. /* Gradient search procedure */
  7.  
  8. __declspec(dllexport) void performMomentum(
  9.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  10.     NSFloat    *weights,    // Pointer to the vector of weights
  11.     int    length,        // Length of the weight vector
  12.     NSFloat    *gradient,    // Pointer to the vector of gradients, one for each weight
  13.     NSFloat    *step,        // Pointer to the learning rate/s
  14.     BOOL    individual,    // Indicates whether their is one learning rate for all weights (FALSE),
  15.                 // or each weight has its own learning rate
  16.     NSFloat    momentum,    // Momentum rate for all weights
  17.     NSFloat    *delta        // Last weight Update
  18.     )
  19. {
  20.     register int i;
  21.  
  22.     for (i=0; i<length; i++)
  23.         weights[i] += delta[i] = momentum*delta[i] + step[individual?i:0]*gradient[i];
  24. }
  25.  
  26. /******************************************/
  27. /* Management of instance data (OPTIONAL) */
  28. /*
  29. __declspec(dllexport) DLLData *allocMomentum(
  30.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  31.     int    length,        // Length of the weight vector
  32.     BOOL    individual    // Indicates whether their is one learning rate for all weights (FALSE),
  33.                 // or each weight has its own learning rate
  34.     )
  35. {
  36.     DLLData *instance = allocDLLInstance(oldInstance);
  37.     return instance;
  38. }
  39.  
  40. __declspec(dllexport) void freeMomentum(DLLData *instance)
  41. {
  42.     freeDLLInstance(instance);
  43. }
  44. */
  45.  
  46.  
  47. /* Activation of component */
  48. __declspec(dllexport) BOOL performPrePost(
  49.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  50.     NSFloat    *input,     // Pointer to the input data
  51.     NSFloat    *output,     // Pointer to the output data
  52.     int rows,         // Number of rows of data
  53.     int cols         // Number of cols of data
  54.     )
  55. {
  56.     int i, length=rows*cols;
  57.     for (i=0; i<length; i++)
  58.         output[i] += input[i];
  59.     return TRUE;    // Return whether to inject this sample or to call performPrePost with another sample
  60. }
  61.  
  62. /******************************************/
  63. /* Management of instance data (OPTIONAL) */
  64. /*
  65. __declspec(dllexport) DLLData *allocPrePost(
  66.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  67.     int *rows,         // Number of rows of output data, can be changed to reflect a diffenent number for the input data
  68.     int *cols,         // Number of cols of output data, can be changed to reflect a diffenent number for the input data
  69.     BOOL preprocessor    // Flag to indicate whether this is a preprocessor or postprocessor
  70.     )
  71. {
  72.     DLLData *instance = allocDLLInstance(oldInstance);
  73.     return instance;
  74. }
  75.  
  76. __declspec(dllexport) void freePrePost(DLLData *instance)
  77. {
  78.     freeDLLInstance(instance); 
  79. }
  80. */